import wx
import random
import os
import time

from playsound import playsound

import pyWinhook
import win32api
import win32con
import pythoncom

# 检测Frame1.py文件中70行代码作用
print([wx.NewId() for _init_ctrls in range(20)])

# 检测Frame1.py文件中381行代码作用
print(os.listdir('scripts')[::-1])

# 检测Frame1.py文件中58行代码作用
print(int(time.time() * 1000))

# 检测Frame1.py文件中462行代码作用
# D:\workspace\KeymouseGo\KeymouseGo
# D:\workspace\KeymouseGo\KeymouseGo\scripts\nihao.txt
print(os.getcwd())
print(os.path.join(os.getcwd(), 'scripts', 'nihao.txt'))

# 检测Frame1.py文件中388行代码作用
text = '10 actions recorded'
action_count = text.replace(' actions recorded', '')
text = '%d actions recorded' % (int(action_count) + 1)
print(text)

def on_mouse_event(event):

    message = event.MessageName
    # 防止移动打印
    if message == 'mouse move':
        return True

    print('MessageName:',event.MessageName)  #事件名称
    print('Message:',event.Message)          #windows消息常量
    print('Time:',event.Time)                #事件发生的时间戳
    print('Window:',event.Window)            #窗口句柄
    print('WindowName:',event.WindowName)    #窗口标题
    print('Position:',event.Position)        #事件发生时相对于整个屏幕的坐标
    print('Wheel:',event.Wheel)              #鼠标滚轮
    print('Injected:',event.Injected)        #判断这个事件是否由程序方式生成，而不是正常的人为触发。
    print('---')

    # 检测Frame1.py文件中350行和351行代码作用
    if message == 'mouse wheel':
        message += ' up' if event.Wheel == 1 else ' down'

    # 如果向上滚轮则退出程序
    if message == 'mouse wheel up': exit()

    return True


def on_keyboard_event(event):
    print('MessageName:',event.MessageName)          #同上，共同属性不再赘述
    print('Message:',event.Message)
    print('Time:',event.Time)
    print('Window:',event.Window)
    print('WindowName:',event.WindowName)
    print('Ascii:', event.Ascii, chr(event.Ascii))   #按键的ASCII码
    print('Key:', event.Key)                         #按键的名称
    print('KeyID:', event.KeyID)                     #按键的虚拟键值
    print('ScanCode:', event.ScanCode)               #按键扫描码
    print('Extended:', event.Extended)               #判断是否为增强键盘的扩展键
    print('Injected:', event.Injected)
    print('Alt', event.Alt)                          #是某同时按下Alt
    print('Transition', event.Transition)            #判断转换状态
    print('---')

    # 按q键退出
    if event.Key.lower() == 'q': exit()
    return True


def main():
    hm = pyWinhook.HookManager()
    hm.MouseAll = on_mouse_event
    hm.KeyAll = on_keyboard_event
    hm.HookMouse()
    hm.HookKeyboard()
    pythoncom.PumpMessages()


# if '__main__' == __name__:
#     main()

# 验证提示音
# print('=================')
# path = os.path.join(os.getcwd(), 'sounds', 'end.mp3')
# print(path)
# playsound(path)



sw = win32api.GetSystemMetrics(win32con.SM_CXSCREEN)
sh = win32api.GetSystemMetrics(win32con.SM_CYSCREEN)
print(f'sw ======> {sw}')
print(f'sh ======> {sh}')
